home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / skykid.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  7KB  |  265 lines

  1. #include "driver.h"
  2. #include "vidhrdw/generic.h"
  3. #include "tilemap.h"
  4.  
  5. unsigned char *skykid_textram, *skykid_videoram;
  6.  
  7. static struct tilemap *background;
  8. static int priority;
  9. static int flipscreen;
  10.  
  11.  
  12. /***************************************************************************
  13.  
  14.     Convert the color PROMs into a more useable format.
  15.  
  16.     The palette PROMs are connected to the RGB output this way:
  17.  
  18.     bit 3    -- 220 ohm resistor  -- RED/GREEN/BLUE
  19.             -- 470 ohm resistor  -- RED/GREEN/BLUE
  20.             -- 1  kohm resistor  -- RED/GREEN/BLUE
  21.     bit 0    -- 2.2kohm resistor  -- RED/GREEN/BLUE
  22.  
  23. ***************************************************************************/
  24.  
  25. void skykid_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  26. {
  27.     int i;
  28.     int bit0,bit1,bit2,bit3;
  29.     int totcolors = Machine->drv->total_colors;
  30.  
  31.     for (i = 0; i < totcolors; i++)
  32.     {
  33.         /* red component */
  34.         bit0 = (color_prom[totcolors*0] >> 0) & 0x01;
  35.         bit1 = (color_prom[totcolors*0] >> 1) & 0x01;
  36.         bit2 = (color_prom[totcolors*0] >> 2) & 0x01;
  37.         bit3 = (color_prom[totcolors*0] >> 3) & 0x01;
  38.         *(palette++) = 0x0e*bit0 + 0x1f*bit1 + 0x43*bit2 + 0x8f*bit3;
  39.  
  40.         /* green component */
  41.         bit0 = (color_prom[totcolors*1] >> 0) & 0x01;
  42.         bit1 = (color_prom[totcolors*1] >> 1) & 0x01;
  43.         bit2 = (color_prom[totcolors*1] >> 2) & 0x01;
  44.         bit3 = (color_prom[totcolors*1] >> 3) & 0x01;
  45.         *(palette++) = 0x0e*bit0 + 0x1f*bit1 + 0x43*bit2 + 0x8f*bit3;
  46.  
  47.         /* blue component */
  48.         bit0 = (color_prom[totcolors*2] >> 0) & 0x01;
  49.         bit1 = (color_prom[totcolors*2] >> 1) & 0x01;
  50.         bit2 = (color_prom[totcolors*2] >> 2) & 0x01;
  51.         bit3 = (color_prom[totcolors*2] >> 3) & 0x01;
  52.         *(palette++) = 0x0e*bit0 + 0x1f*bit1 + 0x43*bit2 + 0x8f*bit3;
  53.  
  54.         color_prom++;
  55.     }
  56.  
  57.     /* text palette */
  58.     for (i = 0; i < 64*4; i++)
  59.         *(colortable++) = i;
  60.  
  61.     color_prom += 2*totcolors;
  62.     /* color_prom now points to the beginning of the lookup table */
  63.  
  64.     /* tiles lookup table */
  65.     for (i = 0; i < 128*4; i++)
  66.         *(colortable++) = *(color_prom++);
  67.  
  68.     /* sprites lookup table */
  69.     for (i = 0;i < 64*8;i++)
  70.         *(colortable++) = *(color_prom++);
  71.  
  72. }
  73.  
  74. /***************************************************************************
  75.  
  76.     Callbacks for the TileMap code
  77.  
  78. ***************************************************************************/
  79.  
  80. static void get_tile_info_bg(int tile_index)
  81. {
  82.     unsigned char code = skykid_videoram[tile_index];
  83.     unsigned char attr = skykid_videoram[tile_index+0x800];
  84.  
  85.     SET_TILE_INFO(1, code + 256*(attr & 0x01),((attr & 0x7e) >> 1) | ((attr & 0x01) << 6));
  86. }
  87.  
  88. /***************************************************************************
  89.  
  90.     Start the video hardware emulation.
  91.  
  92. ***************************************************************************/
  93.  
  94. int skykid_vh_start(void)
  95. {
  96.     background = tilemap_create(get_tile_info_bg,tilemap_scan_rows,TILEMAP_OPAQUE,8,8,64,32);
  97.  
  98.     if (!background)
  99.         return 1;
  100.  
  101.     {
  102.         unsigned char *RAM = memory_region(REGION_CPU1);
  103.  
  104.         spriteram    = &RAM[0x4f80];
  105.         spriteram_2    = &RAM[0x4f80+0x0800];
  106.         spriteram_3    = &RAM[0x4f80+0x0800+0x0800];
  107.         spriteram_size = 0x80;
  108.  
  109.         return 0;
  110.     }
  111. }
  112.  
  113. /***************************************************************************
  114.  
  115.     Memory handlers
  116.  
  117. ***************************************************************************/
  118.  
  119. READ_HANDLER( skykid_videoram_r )
  120. {
  121.     return skykid_videoram[offset];
  122. }
  123.  
  124. WRITE_HANDLER( skykid_videoram_w )
  125. {
  126.     if (skykid_videoram[offset] != data){
  127.         skykid_videoram[offset] = data;
  128.         tilemap_mark_tile_dirty(background,offset & 0x7ff);
  129.     }
  130. }
  131.  
  132. WRITE_HANDLER( skykid_scroll_x_w )
  133. {
  134.     if (flipscreen)
  135.         tilemap_set_scrollx(background, 0, (189 - (offset ^ 1)) & 0x1ff);
  136.     else
  137.         tilemap_set_scrollx(background, 0, ((offset) + 35) & 0x1ff);
  138. }
  139.  
  140. WRITE_HANDLER( skykid_scroll_y_w )
  141. {
  142.     if (flipscreen)
  143.         tilemap_set_scrolly(background, 0, (261 - offset) & 0xff);
  144.     else
  145.         tilemap_set_scrolly(background, 0, (offset + 27) & 0xff);
  146. }
  147.  
  148. WRITE_HANDLER( skykid_flipscreen_w )
  149. {
  150.     priority = data;
  151.     flipscreen = offset;
  152.     tilemap_set_flip(background,flipscreen ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0);
  153. }
  154.  
  155. /***************************************************************************
  156.  
  157.     Display Refresh
  158.  
  159. ***************************************************************************/
  160.  
  161. static void skykid_draw_sprites(struct osd_bitmap *bitmap)
  162. {
  163.     int offs;
  164.  
  165.     for (offs = 0; offs < spriteram_size; offs += 2){
  166.         int number = spriteram[offs] | ((spriteram_3[offs] & 0x80) << 1);
  167.         int color = (spriteram[offs+1] & 0x3f);
  168.         int sx = (spriteram_2[offs+1]) + 0x100*(spriteram_3[offs+1] & 1) - 72;
  169.         int sy = 256 - spriteram_2[offs] - 57;
  170.         int flipy = spriteram_3[offs] & 0x02;
  171.         int flipx = spriteram_3[offs] & 0x01;
  172.         int width, height;
  173.  
  174.         if (flipscreen){
  175.                 flipx = !flipx;
  176.                 flipy = !flipy;
  177.         }
  178.  
  179.         if (number >= 128*3) continue;
  180.  
  181.         switch (spriteram_3[offs] & 0x0c){
  182.             case 0x0c:    /* 2x both ways */
  183.                 width = height = 2; number &= (~3); break;
  184.             case 0x08:    /* 2x vertical */
  185.                 width = 1; height = 2; number &= (~2); break;
  186.             case 0x04:    /* 2x horizontal */
  187.                 width = 2; height = 1; number &= (~1); sy += 16; break;
  188.             default:    /* normal sprite */
  189.                 width = height = 1; sy += 16; break;
  190.         }
  191.  
  192.         {
  193.             static int x_offset[2] = { 0x00, 0x01 };
  194.             static int y_offset[2] = { 0x00, 0x02 };
  195.             int x,y, ex, ey;
  196.  
  197.             for( y=0; y < height; y++ ){
  198.                 for( x=0; x < width; x++ ){
  199.                     ex = flipx ? (width-1-x) : x;
  200.                     ey = flipy ? (height-1-y) : y;
  201.  
  202.                     drawgfx(bitmap,Machine->gfx[2+(number >> 7)],
  203.                         (number)+x_offset[ex]+y_offset[ey],
  204.                         color,
  205.                         flipx, flipy,
  206.                         sx+x*16,sy+y*16,
  207.                         &Machine->drv->visible_area,
  208.                         TRANSPARENCY_COLOR,255);
  209.                 }
  210.             }
  211.         }
  212.     }
  213. }
  214.  
  215. void skykid_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  216. {
  217.     int offs;
  218.  
  219.     tilemap_update(ALL_TILEMAPS);
  220.  
  221.     if (palette_recalc())
  222.         tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
  223.  
  224.     tilemap_render(ALL_TILEMAPS);
  225.  
  226.     tilemap_draw(bitmap,background,0);
  227.     if ((priority & 0xf0) != 0x50)
  228.         skykid_draw_sprites(bitmap);
  229.  
  230.     for (offs = 0x400 - 1; offs > 0; offs--){
  231.         {
  232.             int mx,my,sx,sy;
  233.  
  234.             mx = offs % 32;
  235.             my = offs / 32;
  236.  
  237.             if (my < 2)    {
  238.                 if (mx < 2 || mx >= 30) continue; /* not visible */
  239.                 sx = my + 34;
  240.                 sy = mx - 2;
  241.             }
  242.             else if (my >= 30){
  243.                 if (mx < 2 || mx >= 30) continue; /* not visible */
  244.                 sx = my - 30;
  245.                 sy = mx - 2;
  246.             }
  247.             else{
  248.                 sx = mx + 2;
  249.                 sy = my - 2;
  250.             }
  251.             if (flipscreen){
  252.                 sx = 35 - sx;
  253.                 sy = 27 - sy;
  254.             }
  255.  
  256.             drawgfx(bitmap,Machine->gfx[0],    skykid_textram[offs] + (flipscreen << 8),
  257.                     skykid_textram[offs+0x400] & 0x3f,
  258.                     0,0,sx*8,sy*8,
  259.                     &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  260.         }
  261.     }
  262.     if ((priority & 0xf0) == 0x50)
  263.         skykid_draw_sprites(bitmap);
  264. }
  265.